package com.dmagic.cms.dao;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.dmagic.cms.common.dao.CommonDao;
import com.dmagic.cms.common.util.ListUtil;
import com.dmagic.cms.entity.UploadFileInfo;
import com.dmagic.cms.entity.UploadFileSetInfo;

@Component
public class UploadFileSetInfoDao extends CommonDao<UploadFileSetInfo, Long> {
	@Autowired
	private UploadFileInfoDao uploadFileInfoDao;

	public void deleteById(Long uploadFileSetInfoId) {
		String sql = "select * from  dmagic_upload_fileset_info where uploadFileSetInfoId = ?";
		List<UploadFileSetInfo> uploadFileSetInfos = queryBySQL(sql, UploadFileSetInfo.class,
				uploadFileSetInfoId);
		UploadFileSetInfo uploadFileSetInfo = null;
		if (ListUtil.isNotEmpty(uploadFileSetInfos)) {
			uploadFileSetInfo = uploadFileSetInfos.get(0);
		}
		for (UploadFileInfo uploadFileInfo : uploadFileSetInfo.getUploadFileInfos()) {
			uploadFileInfoDao.deleteEntityById(uploadFileInfo.getUploadFileInfoId());
		}
		deleteEntityById(uploadFileSetInfoId);
	}
}
